package com.sunqizhong.controller;

import com.sunqizhong.entity.Clazz;
import com.sunqizhong.entity.ClazzsQueryParam;
import com.sunqizhong.entity.PageBean;
import com.sunqizhong.entity.Result;
import com.sunqizhong.service.ClazzsService;
import jakarta.servlet.http.HttpServletRequest;
import jdk.jshell.execution.JdiExecutionControlProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ClazzsController {
    @Autowired
    private ClazzsService clazzsService;

    /*
    * 分页查询
    * */
    @GetMapping("/clazzs")
    public Result page(ClazzsQueryParam param){
        log.info("分页查询:{},{},{},{},{}",param.getName(),param.getBegin(),param.getEnd(),param.getPage(),param.getPageSize());
        PageBean pageBean = clazzsService.page(param);

        return Result.success(pageBean);
    }

    /*
    * 添加班级
    * */
    @PostMapping("/clazzs")
    public Result add(@RequestBody Clazz clazz){
        System.out.println("添加部门：" + clazz);
        clazzsService.add(clazz);
        return Result.success();
    }

    /*
    * 根据id查询班级信息
    * */
    @GetMapping("clazzs/{id}")
    public Result getInfo(@PathVariable Integer id){
        System.out.println("根据ID查询部门：" + id);
        Clazz clazz = clazzsService.getInfo(id);
        return Result.success(clazz);
    }

    /*
    * 修改班级
    * */
    @PutMapping("clazzs")
    public Result update(@RequestBody Clazz clazz){
        System.out.println("修改班级数据:" + clazz);
        clazzsService.update(clazz);
        return Result.success();
    }

    /*
    * 删除班级
    * */
    @DeleteMapping("/clazzs/{id}")
    public Result delete(@PathVariable Integer id){
        clazzsService.delete(id);
        System.out.println("根据ID删除班级：" + id);
        return Result.success();
    }

/*    @GetMapping("/clazzs")
    public Result list(){
        List<Clazz> clazzList = clazzsService.list();
        return Result.success(clazzList);
    }*/
}
